package com.lv.thumb.controller;

import com.lv.thumb.common.BaseResponse;
import com.lv.thumb.common.ResultUtils;
import com.lv.thumb.model.entity.Blog;
import com.lv.thumb.model.vo.BlogVO;
import com.lv.thumb.service.BlogService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.apache.pulsar.shade.io.swagger.annotations.Api;
import org.apache.pulsar.shade.io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 *  博客接口
 * 
 * @author lv
 */
@Api(tags = "博客接口")
@RestController
@RequestMapping("blog")
public class BlogController {  
    @Resource
    private BlogService blogService;

    @ApiOperation( value = "获取博客详情", notes = "获取博客详情")
    @GetMapping("/get")
    public BaseResponse<BlogVO> get(long blogId, HttpServletRequest request) {
        BlogVO blogVO = blogService.getBlogVOById(blogId, request);  
        return ResultUtils.success(blogVO);
    }

    /**
     * 获取博客列表
     * @param request 请求
     * @return 博客列表
     * @author lv
     */
    @ApiOperation( value = "获取博客列表", notes = "获取博客列表")
    @GetMapping("/list")
    public BaseResponse<List<BlogVO>> list(HttpServletRequest request) {
        List<Blog> blogList = blogService.list();
        List<BlogVO> blogVOList = blogService.getBlogVOList(blogList, request);
        return ResultUtils.success(blogVOList);
    }

}
